package com.campus.wall.ui.window;


import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.campus.wall.R;

/**
 * <p>
 * .
 * </p>
 *
 * @author Jerry Ou
 * @version 1.0 2015-06-08 19:57
 * @since JDK 1.6
 */
public class PromitDialog extends Dialog {
    Activity activity;
    private Callback callback;
    private String contentTxt;
    private String cancelTxt;
    private String confirmTxt;

    public PromitDialog(@NonNull Activity activity, String contentTxt) {
        super(activity, R.style.CustomDialog);
        this.activity = activity;
        this.contentTxt = contentTxt;
    }


    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    @Override
    public void show() {
        super.show();
        Window window = this.getWindow();
        WindowManager m = activity.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = window.getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.65
        window.setAttributes(p);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCancelable(false);
        setContentView(R.layout.layout_promit_dialog);
        ImageView cancelTxtTv = (ImageView) findViewById(R.id.close);



        if (callback != null) {
            cancelTxtTv.setOnClickListener(v -> callback.confirm());
        }
    }

    public interface Callback {

        void confirm();
    }
}
